<!-- 20220731 待调试 -->

<template>
  <div>
    <div style="text-align: right;">
      <AButton
        type="link"
        @click="openModel"
      >
        规则配置
      </AButton>
    </div>
    <NtdModal
      ref="ntdModal"
      title="规则配置"
    >
      <div style="text-align: right">
        <AButton
          type="link"
          @click="rules.push({})"
        >
          +
        </AButton>
      </div>
      <a-row
        v-for="(rule, _index) in rules"
        :key="_index"
      >
        <a-col :span="4">
          <AInput
            v-model="rule.key"
            addon-before="字段标识"
          />
        </a-col>
        <a-col :span="4">
          <AInput
            v-model="rule.startIndex"
            addon-before="开始下标"
          />
        </a-col>
        <a-col :span="4">
          <AInput
            v-model="rule.endIndex"
            addon-before="结束下标"
          />
        </a-col>
        <a-col :span="4">
          <AInput
            v-model="rule.appendStart"
            addon-before="开始追加"
          />
        </a-col>
        <a-col :span="4">
          <AInput
            v-model="rule.appendEnd"
            addon-before="结束追加"
          />
        </a-col>
        <a-col :span="4">
          转换规则：
          <ASelect
            v-model="rule.enumDataTransform"
            style="width: 50%"
          >
            <a-select-option
              v-for="(dataTransForm, _index) in dataTransForms"
              :key="_index"
              :value="dataTransForm.val"
            >
              {{ dataTransForm.name }}
            </a-select-option>
          </ASelect>
        </a-col>
      </a-row>
    </NtdModal>
  </div>
</template>

<script setup>
import {defineProps, computed, ref} from "vue";
import NtdModal from "../ntd-ant-modal/NtdModal";
import { enumDataTransform } from '@/config/api/api-enums.js'

const props = defineProps({
  formData: {
    type: Array,
    default: () => []
  }
})
const ntdModal = ref()

const rules = ref(props.formData)

const dataTransForms = ref([])

enumDataTransform().then(res => {
  console.log(res)
  dataTransForms.value.push(...res)
})

const openModel = () => {
  ntdModal.value.open()
}

</script>

<style scoped>

</style>